package com.tao.springcloud.controller;

import com.tao.springcloud.entities.CommonResult;
import com.tao.springcloud.entities.Payment;
import com.tao.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName PaymentController
 * @Author HETAO
 * @Date 2020/5/9 10:09
 */
@RestController
@RequestMapping("payment")
@Slf4j
public class PaymentController {

    @Resource
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @PostMapping
    public CommonResult<Payment> createPayment(@RequestBody Payment payment) {
        int count = paymentService.createPayment(payment);
        if (count == 1) {
            log.info("添加订单成功,{}"+payment);
            return new CommonResult<>(200,"添加订单成功");
        }
        log.error("添加订单失败");
        return new CommonResult<>(400,"添加订单失败");
    }


    @GetMapping("get")
    public CommonResult<Payment> getPaymentById(@RequestParam("id") Long id) {
        Payment payment = paymentService.getPaymentById(id);
        if (payment != null) {
            log.info("查询成功,<===>{}"+payment);
            return new CommonResult<>(200,"查询成功《++++++》"+"端口:"+serverPort,payment);
        }
        return new CommonResult<>(404,"查询失败",null);
    }

}
